//
//  LeverCommonCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/24.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class LeverCommonCell: BaseCollectionViewCell {
    lazy var nameLabel: BaseLabel = {
        let label = BaseLabel(style: .twiceStyle)
        label.themeBackground = ThemeManager.ThemeColorKeys.background2
        label.font = UIFont.systemFont(ofSize: 12)
        label.textAlignment = NSTextAlignment.center
        label.layer.cornerRadius = 2;
        label.layer.borderColor = KTableLineColor.cgColor
        label.layer.borderWidth = 0.5
        return label
    }()
    
    lazy var priceBtn: UIButton = {
        let btn = UIButton()
        btn.titleLabel?.textAlignment = NSTextAlignment.center
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        btn.layer.borderWidth = 0.5
        btn.layer.cornerRadius = 3
        return  btn
    }()
    
    lazy var kindLabel: UILabel = {
        let label = BaseLabel(style: .twiceStyle)
        label.font = UIFont.systemFont(ofSize: 12)
        label.text = "%"
        label.isHidden = true
        label.textAlignment = NSTextAlignment.center
        return label
    }()
    
    lazy var arrowDown : UIImageView  = {
        let imageView = UIImageView()
        imageView.isHidden = true
        imageView.image = UIImage(named: "leverDown")
        return imageView
    }()
    
    override func setUpUI() {
        self.titleLabel.font = UIFont.systemFont(ofSize: 12)
        self.titleLabel.isHidden = true
        self.titleLabel.textAlignment = NSTextAlignment.center
        self.contentView.addSubview(self.titleLabel)
        self.titleLabel.layer.cornerRadius = 2;
        self.titleLabel.layer.borderColor = KTableLineColor.cgColor
        self.titleLabel.layer.borderWidth = 0
        self.titleLabel.snp.remakeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(15)
        }
        
        self.contentView.addSubview(priceBtn)
        priceBtn.isHidden = true
        priceBtn.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
        }
        
        
        self.contentView.addSubview(nameLabel)
        nameLabel.isHidden = true
        nameLabel.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
        }
        
        self.selectImage.image = UIImage(named: "coinSelect")
        self.selectImage.isHidden = true
        self.contentView.addSubview(self.selectImage)
        self.selectImage.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.right.equalToSuperview()
        }
        
        self.addSubview(kindLabel)
        kindLabel.snp.makeConstraints { (make) in
           make.right.equalToSuperview()
           make.centerY.equalToSuperview()
        }
        
        nameLabel.addSubview(arrowDown)
        arrowDown.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
        }
    }
    
    func changePriceBtn(index:Int,isSelected:Bool) {
        if index == 1 {
            if isSelected {
            self.priceBtn.setTitleColor(UIColor(hexStr: "#ffffff"), for: UIControlState.normal)
            self.priceBtn.backgroundColor = kGreenColor
            self.priceBtn.layer.borderColor = kGreenColor.cgColor
            }else {
                self.priceBtn.setTitleColor(kGreenColor, for: UIControlState.normal)
                self.priceBtn.backgroundColor = UIColor.clear
                self.priceBtn.layer.borderColor = kGreenColor.cgColor
            }
            
        }else if index == 2{
            if !isSelected {
                self.priceBtn.setTitleColor(UIColor(hexStr: "#ffffff"), for: UIControlState.normal)
                self.priceBtn.backgroundColor = kRedColor
                self.priceBtn.layer.borderColor = kGreenColor.cgColor
            }else {
                
                self.priceBtn.setTitleColor(kGreenColor, for: UIControlState.normal)
                self.priceBtn.backgroundColor = UIColor.clear
                self.priceBtn.layer.borderColor = kGreenColor.cgColor
            }
            
        }
    }
    
}
